<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>我的订单</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<link type="text/css" rel="stylesheet" href="statics/css/style.css" />


<script type="text/javascript" src="/EasyBuy/statics/js/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="/EasyBuy/statics/js/menu.js"></script>

<script type="text/javascript" src="/EasyBuy/statics/js/select.js"></script>


<title>尤洪</title>
</head>
<body>
	<c:choose>
	  	<c:when test="${empty applicationScope.id}">
	  		<% response.sendRedirect("/EasyBuy/pre/Login.jsp");%>
	  	</c:when>
	  	<c:otherwise>
	  		<%@ include file="../../common/header.jsp" %>
			<%@ include file="../../common/backendHeader.jsp" %>
			<div class="i_bg bg_color">
			 <c:choose>
				<c:when test="${empty applicationScope.type }">
					<% 	request.getRequestDispatcher("../../UserServlet?opr=type&href=Member_Address&href1=order").forward(request, response); %>
				</c:when>
				<c:otherwise>
					<c:if test="${applicationScope.type==1 }">
		  				<%@ include file="../../common/sideMamber.jsp" %> 
					</c:if>
					<c:if test="${applicationScope.type==0 }">
						<%@ include file="../../common/sideUser.jsp" %> 
					</c:if>
				</c:otherwise>
			 </c:choose>
	  	</c:otherwise>
  	</c:choose>
	
	
	
			<div class="m_right">
				<p></p>
				<div class="mem_tit">我的订单</div>
				<table border="0" class="order_tab"
					style="width:930px; text-align:center; margin-bottom:30px;"
					cellspacing="0" cellpadding="0" id="tab">
					<tr>
						<td width="20%">订单号</td>
						<td width="25%">下单时间</td>
						<td width="15%">订单总金额</td>
						<td width="25%">订单状态</td>
						<td width="15%">操作</td>
					</tr>
					
				</table>


				<div class="mem_tit">合并订单</div>
				<table border="0" class="order_tab" style="width:930px;"
					cellspacing="0" cellpadding="0">
					<tr>
						<td width="135" align="right">主订单</td>
						<td width="220"><select id="ij" name="order1">
								<option value="0" >请选择...</option>
								
						</select></td>
						<td width="135" align="right">从订单</td>
						<td width="220"><select id="jj" name="order2">
								<option value="0" >请选择...</option>
								
						</select></td>
						<td><div class="btn_u">
								<span id="ding">合并订单</span>
							</div>
						</td>
					</tr>
					<tr>
						<td>&nbsp;</td>
						<td colspan="4"
							style="font-family:'宋体'; padding:20px 10px 50px 10px;">
							订单合并是在发货前将相同状态的订单合并成一新的订单。 <br /> 收货地址，送货方式等以主定单为准。</td>
					</tr>
				</table>


			</div>
		</div>
		<!--End 用户中心 End-->
		<!--Begin Footer Begin -->
		<%@ include file="../../common/footer.jsp" %>
<script type="text/javascript" src="/EasyBuy/statics/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
	$(document).ready(function(){
		//获取个人信息
		function cha(){
			$.getJSON("OrderServlet","opr=MyDing&uid=${applicationScope.id}",function(data){
				for(var i=0; i<data.length;i++){
				//订单状态
				var status=null;
				if(data[i].status==1){
					status="待审核";
				}else if(data[i].status==2){
					status="审核通过";
				}else if(data[i].status==3){
					status="配货";
				}else if(data[i].status==4){
					status="卖家已发货";
				}else if(data[i].status==5){
					status="已收货";
				}
				var type=null;
				 //交替类型0.取消订单 1.已确定
				 if(data[i].type==0){
				 	type="取消订单";
				 }else if(data[i].type==1){
				 	type="已确定";
				 }
	  				$("#tab").append("<tr><td><font color='#ff4e00'>"+data[i].serialNumber+"</font></td><td>"+data[i].createTime+"</td><td>￥"+data[i].cost+"</td><td>"+status+"</td><td>"+type+"</td></tr>");
	  				$("#ij").append("<option value='"+(i+1)+"'>"+data[i].serialNumber+"</option>");
	  				$("#jj").append("<option value='"+(i+1)+"'>"+data[i].serialNumber+"</option>");
	  			}
			});
		}
		cha();//获取个人信息
		//下拉框事件
    		select_a=document.getElementById("ij");
		    select_b=document.getElementById("jj");
		    s_a_child=select_a.children;
		    s_b_child=select_b.children;
		    //创建三个变量，用来分别接收被选中的option的索引值
		    var a= 0,b= 0,c=0;
		    //当selection标签发生状态改变时
		    select_a.onchange=function(){
		        //循环遍历selection标签
		        for (var i=0;i<s_a_child.length;i++) {
		            //当检测到有标签处于选中状态时
		            if (s_a_child[i].selected) {
		                //先把上一个被选中的option标签的disabled变为false
		                s_b_child[i].disabled=false;
		                //再存储这次选中的option标签的索引值
		                a=i;
		                //再把这次选中的标签的索引值得option的disabled变为true
		                s_b_child[i].disabled=true;
		            }
		        };
		    };
		    select_b.onchange=function(){
		        for (var i=0;i<s_b_child.length;i++) {
		            if (s_b_child[i].selected) {
		                s_a_child[b].disabled=false;
		                b=i;
		                s_a_child[i].disabled=true;
		            }
		        }
		    };
		$("#ding").click(function(){
		//获取选中的option
			var order1=$("#ij option:selected").text();  //主订单
			var order2=$("#jj option:selected").text();  //从订单
			if($("#ij option:selected").val()==0||$("#jj option:selected").val()==0){
				alert("请选择要合并的订单");
			}else{
				$.get("OrderServlet","opr=he&order2="+order2+"&order1="+order1,function(date){	
						//$("#tab tr:gt(0)").html("");
						if(date=="合并成功"){
							alert(date);
							location.href="/EasyBuy/backend/order/Member_Order.jsp";
						}else{
							alert(date);
						}
				});
			}
		});
	});
	
</script>
</body>
</html>
